﻿//-----------------------------------------------------------------------
// <copyright file="LocalizedStrings.cs" company="FIT VUT">
//     Copyright (c) FIT VUT. All rights are reserved.
// </copyright>
//----------------------------------------------------------------------

using System;
using System.Globalization;
using System.Net;
using System.Reflection;
using System.Resources;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Knihotoc_WP8.Localization
{
    public class LocalizedStrings : IValueConverter
    {
        #region Private fields
        private static readonly ResourceManager InstanceResourceManager = new ResourceManager(
                                                                                      "Knihotoc_WP8.Localization.LocalizationResources",
                                                                                      Assembly.GetExecutingAssembly());

        /// <summary>
        /// Use this property to specify the culture
        /// </summary>
        private static CultureInfo uiCulture = Thread.CurrentThread.CurrentUICulture;
        #endregion

        #region Public properties
        /// <summary>
        /// Gets or sets the current culture of the application.
        /// </summary>
        public static CultureInfo UiCulture
        {
            get { return uiCulture; }
            set { uiCulture = value; }
        }
        #endregion

        /// <summary>
        /// This method returns the localized string of the given resource.
        /// </summary>
        /// <param name="resource">Name of the resource to be returned.</param>
        /// <returns>Localized string.</returns>
        public static string Get(string resource)
        {
            return InstanceResourceManager.GetString(resource, UiCulture);
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var reader = (LocalizedStrings)value;
            
            return Get((string)parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // ConvertBack is not used, because the Localization is only a One Way binding
            throw new NotImplementedException();
        }
    }
}
